import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_widget/custom/custom_appbar.dart';

// ignore: camel_case_types, must_be_immutable
class BottomSheetPage extends StatefulWidget {
  String name;
  BottomSheetPage({Key? key, required this.name}) : super(key: key);

  @override
  _BottomSheetPageState createState() => _BottomSheetPageState();
}

// ignore: camel_case_types
class _BottomSheetPageState extends State<BottomSheetPage> {
  final List list = [
    {'name': '文本A'},
    {'name': '文本B'},
    {'name': '文本C'},
  ];
  Future<void> showBottomSheet() async {
    final res = await showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return SizedBox(
          height: 300,
          // ignore: prefer_const_literals_to_create_immutables
          child: Column(
            children: list
                .map(
                  (e) => ListTile(
                    title: Text(e['name']),
                    onTap: () {
                      Navigator.pop(context, e['name']);
                    },
                  ),
                )
                .toList(),
          ),
        );
      },
    );
    // ignore: avoid_print
    print(res);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // ignore: deprecated_member_use
            ElevatedButton(
              onPressed: showBottomSheet,
              child: const Text(
                "BottomSheet 底部弹出框",
                style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
